package org.robotlegs.mvcs
{
	import flash.events.Event;
	import flash.events.IEventDispatcher;
	
	import org.robotlegs.base.EventMap;
	import org.robotlegs.core.IEventMap;
	
	/**
	 * 
     * 所有的框架 actor 都可以发送事件: Mediator, Service, Model, 和 Command.
	 * Mediator 是唯一接收框架事件的actor. 
	 * Command 是在对框架事件的处理中被触发. 
	 * 一个事件既可以被一个 Mediator 接收, 也可以触发一个 command.
	 *
	 * model 和 service 不应该监听和处理事件. 这样做会把它们紧耦合到应用程序特有逻辑而降低潜在的便携性和复用性.
	 * 
	 */
public class Actor
{

	protected var _eventDispatcher:IEventDispatcher;

	protected var _eventMap:IEventMap;
	

	

	public function get eventDispatcher():IEventDispatcher { return _eventDispatcher; }
	
	[Inject]
	public function set eventDispatcher(value:IEventDispatcher):void{_eventDispatcher = value;}
	

	
	
	protected function get eventMap():IEventMap
	{
		return _eventMap || (_eventMap = new EventMap(eventDispatcher));
	}
	

	protected function dispatch(event:Event):Boolean
	{
		if(eventDispatcher.hasEventListener(event.type))
			return eventDispatcher.dispatchEvent(event);
		return false;
	}
}
}
